load libraries

library("tidyverse")
library("plyr")
library("dplyr")
library("ggplot2")
library("RColorBrewer")
#library("scales")
#library("ggpubr")
#library("gridExtra")
#library("grid")
#library("GGally")
library("data.table")
library("stringr")
library("janitor")
library("knitr")
library("kableExtra")
library("plotly") 

knitr::opts_chunk$set(echo = TRUE, warning = FALSE, message = FALSE)
                 #    fig.width = 20,
                  #    fig.asp = 0.6,
                   #   out.width = "100%")
data <- read.csv("/Users/nuriteliash/Documents/GitHub/varroa_ploidy/data/ploidy.csv") %>%
  dplyr::mutate(Family = as.character(Family))

# order the levels 
data$body.part <- factor(data$body.part, level=c("Body", "Anterior", "Posterior", "Legs","Hemolymph","Ovary","Testes"))

data$Stage <- factor(data$Stage, level=c("Larvae", "Protonymph", "Deuteronymph", "adult"))

data$Stage_original <- factor(data$Stage_original, level=c("Mom", "Son", "Mature","Daughter", "Deuteronymph", "Protonymph", "Larvae", "Immature"))

p_fem = data %>% dplyr::filter(Sex == "fem") %>%
  dplyr::filter(body.part %in% c("Body", "Legs","Ovary","Testes")) %>%
  ggplot(aes(y=ploidy, x=body.part, fill = Sex)) + 
 geom_boxplot() +  theme_bw() +  geom_jitter(width=0.1, size=2) +
  facet_wrap(~Stage, nrow = 1) +  ggtitle('Female mite ploidy') +
  ylim(0, 3)

p_male = data %>% dplyr::filter(Sex == "male") %>%
  dplyr::filter(body.part %in% c("Body", "Legs","Ovary","Testes")) %>%
  ggplot(aes(y=ploidy, x=body.part, fill = Sex)) + 
 geom_boxplot(fill = "#00AFBB") +  theme_bw() +  geom_jitter(width=0.1, size=2,color = "#00AFBB",fill = "#00AFBB") +
  facet_wrap(~Stage, nrow = 1) +  ggtitle('Male mite ploidy') +
  ylim(0, 3)

p_adult = data %>% dplyr::filter(Stage == "adult") %>%
  ggplot(aes(y=ploidy, x=body.part, fill = Sex, lable = Stage)) + 
 geom_boxplot(outlier.shape = NA, coef=0 ) +  theme_bw() +  geom_jitter(width=0.1, size=2) +
  facet_wrap(~Sex) + ggtitle('Adult mite ploidy') +  ylim(0, 3)


p_1 = data %>% dplyr::filter(Stage == "adult") %>%
  ggplot(aes(y=ploidy, x=body.part, fill = Sex, lable = Stage)) + 
 geom_boxplot(outlier.shape = NA, coef=0 ) +  theme_bw() +  geom_jitter(width=0.1, size=2) + 
  ggtitle('Adult mite ploidy') +  ylim(0, 3)


p_all_stages = data %>% dplyr::filter(Stage != "NA" ) %>%
dplyr::filter(body.part %in% c("Body", "Legs", "Ovary","Testes")) %>%
  ggplot(aes(y=ploidy, x=body.part, fill = Sex, lable = Stage)) + 
 geom_boxplot(outlier.shape = NA, coef=0 ) +  theme_bw() +  geom_jitter(width=0.1, size=2) + 
   facet_wrap(~Stage, nrow = 1) + ggtitle('Mite ploidy, in different stages') +
  theme(axis.text.x = element_text(angle = 45)) +  theme(legend.position='none')+  ylim(0, 3)


p_family_allStages = data %>% dplyr::filter(body.part %in% c("Body", "Ovary","Testes")) %>%
    mutate_at("Family", ~replace_na(.,"0")) %>%
  ggplot(aes(y=ploidy, x=Family, fill = Sex, lable = Stage)) + 
 geom_boxplot(outlier.shape = NA, coef=0 ) +  theme_bw() +  geom_jitter(width=0.1, size=2) +
  facet_wrap(~body.part+Stage ) + ggtitle('Mite ploidy per family') +  ylim(0, 3)

p_fam_body = data %>% dplyr::filter(body.part == "Body") %>%
 dplyr::filter(Stage %in% c("Larvae", "Protonymph", "Deuteronymph", "adult")) %>%
  dplyr::filter(Family %in% c("1", "11","27","3","2","4", "5")) %>%
  ggplot(aes(y=ploidy, x=Stage, fill = Sex, lable = Stage)) + 
 geom_boxplot(outlier.shape = NA, coef=0 ) +  theme_bw() +  geom_jitter(width=0.1, size=2) +
  facet_wrap(~Family ) + ggtitle('Mite ploidy per family') +
   theme(axis.text.x = element_text(angle = 45)) +  theme(legend.position='none')+  ylim(0, 3)


p_fam_body_1_11_27_3 = data %>% dplyr::filter(body.part == "Body") %>%
  dplyr::filter(Family %in% c("1", "11","27","3")) %>%
  ggplot(aes(y=ploidy, x=Stage_original, fill = Sex, lable = Stage_original)) + 
 geom_boxplot(outlier.shape = NA, coef=0 ) +  theme_bw() +  geom_jitter(width=0.1, size=2) +
  facet_wrap(~Family , nrow = 1) + ggtitle('Mite ploidy per family') +
   theme(axis.text.x = element_text(angle = 45)) +  theme(legend.position='none')+  ylim(0, 3)


p_fam_body_2_4 = data %>% dplyr::filter(body.part == "Body") %>%
  dplyr::filter(Family %in% c("2","4")) %>%
  ggplot(aes(y=ploidy, x=Stage_original, fill = Sex, lable = Stage_original)) + 
 geom_boxplot(outlier.shape = NA, coef=0 ) +  theme_bw() +  geom_jitter(width=0.1, size=2) +
  facet_wrap(~Family ) + ggtitle('Mite ploidy per family') +
   theme(axis.text.x = element_text(angle = 45)) +  theme(legend.position='none')+  ylim(0, 3)


p_fam_body_5 = data %>% dplyr::filter(body.part == "Body") %>%
  dplyr::filter(Family == "5") %>%
  ggplot(aes(y=ploidy, x=Stage_original, fill = Sex, lable = Stage_original)) + 
 geom_boxplot(outlier.shape = NA, coef=0 ) +  theme_bw() +  geom_jitter(width=0.1, size=2) +
  facet_wrap(~Family ) + ggtitle('Mite ploidy per family') +
   theme(axis.text.x = element_text(angle = 45)) +  theme(legend.position='none')+  ylim(0, 3)

all developmental stages, males and females, in different body parts


Looking at specific families

the ploidy of the male offspring varied, depends on the family

for some families ( 1, 11, 27 and 3) the females ploidy was higher then males.
while females looks diploid, males look haploid.


for other families ( 2 and 4) the females ploidy was similar to that of the male offspring.


in one family (number 5) the male offspring ploidy was mixed:
one males look diploid, and the other two look haploid.